{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.random.random(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.9841867 , 0.92297763, 0.44735377, 0.69758577, 0.42204065,\n",
       "       0.61293605, 0.30767345, 0.39755511, 0.06708919, 0.5183648 ,\n",
       "       0.38253798, 0.15923913])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "A = a.reshape(3, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.9841867 , 0.92297763, 0.44735377, 0.69758577],\n",
       "       [0.42204065, 0.61293605, 0.30767345, 0.39755511],\n",
       "       [0.06708919, 0.5183648 , 0.38253798, 0.15923913]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.9841867 , 0.92297763, 0.44735377, 0.69758577, 0.42204065,\n",
       "       0.61293605, 0.30767345, 0.39755511, 0.06708919, 0.5183648 ,\n",
       "       0.38253798, 0.15923913])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 直接改变a的形状\n",
    "a.shape = (3, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.9841867 , 0.92297763, 0.44735377, 0.69758577],\n",
       "       [0.42204065, 0.61293605, 0.30767345, 0.39755511],\n",
       "       [0.06708919, 0.5183648 , 0.38253798, 0.15923913]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.9841867 , 0.92297763, 0.44735377, 0.69758577, 0.42204065,\n",
       "       0.61293605, 0.30767345, 0.39755511, 0.06708919, 0.5183648 ,\n",
       "       0.38253798, 0.15923913])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.ravel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "a.shape = (12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.9841867 , 0.92297763, 0.44735377, 0.69758577, 0.42204065,\n",
       "       0.61293605, 0.30767345, 0.39755511, 0.06708919, 0.5183648 ,\n",
       "       0.38253798, 0.15923913])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.9841867 , 0.42204065, 0.06708919],\n",
       "       [0.92297763, 0.61293605, 0.5183648 ],\n",
       "       [0.44735377, 0.30767345, 0.38253798],\n",
       "       [0.69758577, 0.39755511, 0.15923913]])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 矩形转置\n",
    "A.transpose()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
